import request from "@/axios/axios.ts";
import request_doc from "@/axios/request_doc.ts";
import {
    DIYFileCRUD, DIYReturnData,
    InboundAndOutbound,
    InboundAndOutboundAndHandle, InboundAndOutboundAndInventory, InboundList, SummaryTable,
} from "@/api/first/ExportFile/type.ts";
import {useStore} from '@/pinia'
const store = useStore()

enum API1 {
    IN_OUT = '/first/inbound_and_outbound_file',
    IN_OUT_HANDLE = '/first/in_out_team',
    IN_OUT_INVENTORY = '/first/inbound_and_outbound_and_inventory',
    DIY = '/first/specifies_the_part_export',
    DIT_TABLE = '/first/return_part_export',

    SummaryTable = '/first/summary_table',
    Table02 = '/first/in_out_team_return_table',
    Table04 = '/first/backhand_table4_make',
    InboundList = '/first/inbound_list'
}
enum API2 {
    IN_OUT = '/second/inbound_and_outbound_file',
    IN_OUT_HANDLE = '/second/in_out_team',
    IN_OUT_INVENTORY = '/second/inbound_and_outbound_and_inventory',
    DIY = '/second/specifies_the_part_export',
    DIT_TABLE = '/second/return_part_export',

    SummaryTable = '/second/summary_table',
    Table02 = '/second/in_out_team_return_table',
    Table04 = '/second/backhand_table4_make',
    InboundList = '/second/inbound_list'
}
enum API3 {
    IN_OUT = '/first_new/inbound_and_outbound_file',
    IN_OUT_HANDLE = '/first_new/in_out_team',
    IN_OUT_INVENTORY = '/first_new/inbound_and_outbound_and_inventory',
    DIY = '/first_new/specifies_the_part_export',
    DIT_TABLE = '/first_new/return_part_export',

    SummaryTable = '/first_new/summary_table',
    Table02 = '/first_new/in_out_team_return_table',
    Table04 = '/first_new/backhand_table4_make',
    InboundList = '/first_new/inbound_list'
}

// ======================================
// 表格01 出入库和库存表
// ======================================
export const reqInAndOut = (data: InboundAndOutbound): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.IN_OUT, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.IN_OUT, data)
    else
        return request.post<any, any>(API3.IN_OUT, data)
}

// ======================================
// 表格02 出入库和库存表(按照供应方或者领用方排序)
// ======================================
export const reqInAndOutAndHandle = (data: InboundAndOutboundAndHandle): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.IN_OUT_HANDLE, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.IN_OUT_HANDLE, data)
    else
        return request.post<any, any>(API3.IN_OUT_HANDLE, data)
}

// 直接返回02表的excel文件
export const req02Table = (data: InboundAndOutboundAndHandle): Promise<any> => {
    if(store.axios_path === '1')
        return request_doc.post<any, any>(API1.Table02, data)
    else if(store.axios_path === '2')
        return request_doc.post<any, any>(API2.Table02, data)
    else
        return request_doc.post<any, any>(API3.Table02, data)
}

// ======================================
// 表格03 出库，入库，当前库存
// ======================================
export const reqInAndOutAndInventory = (data: InboundAndOutboundAndInventory): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.IN_OUT_INVENTORY, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.IN_OUT_INVENTORY, data)
    else
        return request.post<any, any>(API3.IN_OUT_INVENTORY, data)
}

// ======================================
// 表格04 出库，入库，当前库存
// ======================================
// 自定义导出表格所含小类的种类
export const reqDIYCRUD = (data: DIYFileCRUD): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.DIY, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.DIY, data)
    else
        return request.post<any, any>(API3.DIY, data)
}

export const reqDIYTable = (data: DIYReturnData): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.DIT_TABLE, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.DIT_TABLE, data)
    else
        return request.post<any, any>(API3.DIT_TABLE, data)
}

// 返回后端生成的自定义表格
export const req04Table = (data: DIYReturnData): Promise<any> => {
    if(store.axios_path === '1')
        return request_doc.post<any, any>(API1.Table04, data)
    else if(store.axios_path === '2')
        return request_doc.post<any, any>(API2.Table04, data)
    else
        return request_doc.post<any, any>(API3.Table04, data)
}

// ======================================
// 库位检查和间隔日期检查
// ======================================


// ======================================
// 表格05 直接导出总表，不在页面上显示
// ======================================
export const reqSummaryTable = (data: SummaryTable): Promise<any> => {
    if(store.axios_path === '1')
        return request_doc.post<any, any>(API1.SummaryTable, data)
    else if(store.axios_path === '2')
        return request_doc.post<any, any>(API2.SummaryTable, data)
    else
        return request_doc.post<any, any>(API3.SummaryTable, data)
}

// ======================================
// table07 导出选择的入库单
// ======================================
export const reqInboundList = (data: InboundList): Promise<any> => {
    if(store.axios_path === '1')
        return request_doc.post<any, any>(API1.InboundList, data)
    else if(store.axios_path === '2')
        return request_doc.post<any, any>(API2.InboundList, data)
    else
        return request_doc.post<any, any>(API3.InboundList, data)
}
